package yancy.modules.sys.entity;


import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import yancy.common.validator.group.AddGroup;
import yancy.common.validator.group.UpdateGroup;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
@TableName("sys_borrow_log")
public class SysBorrowLog {
    @TableId
    @NotNull(message = "logId不能为空", groups = {UpdateGroup.class})
    private Long logId;
    @NotNull(message = "userId不能为空", groups = {AddGroup.class, UpdateGroup.class})
    private Long userId;
    @NotNull(message = "bookId不能为空", groups = {AddGroup.class, UpdateGroup.class})
    private Long bookId;
    private Integer type;
    @NotNull(message = "total不能为空", groups = {AddGroup.class, UpdateGroup.class})
    private Integer total;
    private Integer status;
    private Long createUserId;
    private Date createTime;

    public static final int TYPE_BORROW = 1;
    public static final int TYPE_BACK = 2;

    public SysBorrowLog(Long logId, Long userId, Long bookId, Integer type, Integer total, Integer status, Long createUserId, Date createTime) {
        this.logId = logId;
        this.userId = userId;
        this.bookId = bookId;
        this.type = type;
        this.total = total;
        this.status = status;
        this.createUserId = createUserId;
        this.createTime = createTime;
    }

    public SysBorrowLog(Long userId, Long bookId, Integer type, Integer total, Integer status, Long createUserId, Date createTime) {
        this.userId = userId;
        this.bookId = bookId;
        this.type = type;
        this.total = total;
        this.status = status;
        this.createUserId = createUserId;
        this.createTime = createTime;
    }

    public SysBorrowLog() {


    }

    public static SysBorrowLog OfBorrow(Long userId, Long bookId, Integer total, Long createUserId) {
        return new SysBorrowLog(userId, bookId, TYPE_BORROW, total, 1, createUserId, new Date());

    }

    public static SysBorrowLog OfBack(Long userId, Long bookId, Integer total, Long createUserId) {
        return new SysBorrowLog(userId, bookId, TYPE_BACK, total, 1, createUserId, new Date());

    }
}
